<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model {

	public $table = 'user';
	
	function saveUser($data){
		if($this->getUserInfo($data['email'])){
			$query = $this->db->update($this->table, $data, "email = '".$data['email']."'");
		}else{
			$query = $this->db->insert($this->table, $data);
		}
		return $query;
	}
	
	function getUserInfo($email){
		$query = $this->db->select('*')->from('user')->where('email', $email)->get();
		return $query->result();
	}
	
	function setAcceptFlg($value, $user_id){
		if($value != '1') $value = '0';
		$data['accept_flg'] = $value;
		$query = $this->db->update($this->table, $data, "id = ".$user_id);
		return $query;
	}
	
	function setPassword($pass, $user_id){
		$data['password'] = $pass;
		$query = $this->db->update($this->table, $data, "id = ".$user_id);
		return $query;
	}
}